package com.jm.product.controller;

import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.collect.Maps;
import com.jm.product.controller.core.BaseController;
import com.jm.product.entity.Product;

/**
 * 产品管理Controller
 * @author sunshine
 * @version 2017-07-04
 */
@Controller
@RequestMapping(value = "product/product")
public class ProductController extends BaseController<Product,Integer> {

	protected String listPage() {

		return "product/productList";
	}

	public String form(Product product, Model model) {
		if (null != product && null != product.getId()){
			this.data = service.getById(product.getId());
			model.addAttribute("product", this.data);
		}
		return "product/productForm";
	}

	public String savePage() {

		return "redirect:/product/product/?repage";
	}

	@RequestMapping("checkIsInUse")
	@ResponseBody
	public Map<String, Object> checkProduct(@RequestParam Integer productid) {
		Map<String, Object> map = Maps.newHashMap() ;
		log.debug("productid : "+productid);
		boolean isUse = false ; //TODO: 需要实现
		if (isUse){
			map.put(SUCCESS, true) ;
		} else {
			map.put(SUCCESS, false);
		}
		return map ;
	}
}
